package com.jinmdz.fmis.api.api.controller;

import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.model.common.IdListData;
import com.jinmdz.fmis.api.api.model.funeral.BusinessCodeData;
import com.jinmdz.fmis.api.api.model.settlement.*;
import com.jinmdz.fmis.api.api.service.ChargeSettlementInvoiceService;
import com.jinmdz.fmis.api.api.service.ChargeSettlementRefundService;
import com.jinmdz.fmis.api.api.service.ChargeSettlementService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 费用结算相关接口
 *
 * @author LiCongLu
 * @date 2020-02-18 14:07
 */
@Api(description = "费用结算相关接口")
@RestController()
@RequestMapping("/api/charge-settlement")
public class ChargeSettlementController extends BaseController {

    @Resource
    private ChargeSettlementService chargeSettlementService;

    @Resource
    private ChargeSettlementRefundService chargeSettlementRefundService;

    @Resource
    private ChargeSettlementInvoiceService chargeSettlementInvoiceService;

    /**
     * 根据funeral_dead表中businessCode加载逝者费用结算页面所有信息
     *
     * @param data 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-02-18 14:16
     */
    @ApiOperation(value = "根据funeral_dead表中businessCode加载逝者费用结算页面所有信息，此接口为按页面定制接口", notes = "根据businessCode加载火化逝者信息，信息包括：逝者信息、逝者家属信息、承办人信息，费用明细和结算历史记录信息")
    @PostMapping("/load-charge-settlement-all")
    public BaseResult<ChargeSettlementAllItem> loadChargeSettlementAll(@RequestBody BusinessCodeData data) {
        return resultHandler(data, userItem -> chargeSettlementService.loadChargeSettlementAll(data));
    }

    /**
     * 根据费用id加载费用记录信息
     *
     * @param data 费用主键
     * @return
     * @author LiCongLu
     * @date 2020-02-18 15:07
     */
    @ApiOperation(value = "根据费用id加载费用记录信息", notes = "根据费用id从表charge_item中加载指定费用记录信息")
    @PostMapping("/load-charge-item-with-id")
    public BaseResult<ChargeItemData> loadChargeItemWithId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> chargeSettlementService.loadChargeItemWithId(data));
    }

    /**
     * 保存根据费用id加载的费用记录信息
     *
     * @param data 费用请求数据
     * @return
     * @author LiCongLu
     * @date 2020-02-18 15:42
     */
    @ApiOperation(value = "保存根据费用id加载的费用记录信息", notes = "保存根据费用id加载的费用记录信息到表charge_item中")
    @PostMapping("/save-charge-item-with-id")
    public BaseResult<ChargeItemData> saveChargeItemWithId(@RequestBody ChargeItemData data) {
        return resultHandler(data, userItem -> chargeSettlementService.saveChargeItemWithId(userItem, data));
    }

    /**
     * 根据提供的费用项目id进行费用结算
     *
     * @param data 结算保存数据
     * @return
     * @author LiCongLu
     * @date 2020-02-19 11:00
     */
    @ApiOperation(value = "根据提供的费用项目id进行费用结算", notes = "根据提供的charge_item表中id集合信息，进行费用结算处理，成功后返回结算记录")
    @PostMapping("/save-charge-settle-to-settle-accounts")
    public BaseResult saveChargeSettleToSettleAccounts(@RequestBody ChargeAccountsData data) {
        return resultHandler(data, userItem -> chargeSettlementService.saveChargeSettleToSettleAccounts(userItem, data));
    }

    /**
     * 取消结算，即删除费用结算
     *
     * @param data 结算主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-02-20 11:35
     */
    @ApiOperation(value = "取消结算", notes = "对费用表charge_settle中已结算记录id，进行退费操作，系统将产生未结算的退费记录信息")
    @PostMapping("/save-charge-settle-to-cancellation-settlement")
    public BaseResult saveChargeSettleToCancellationSettlement(@RequestBody IdListData data) {
        return resultHandler(data, userItem -> chargeSettlementService.saveChargeSettleToCancellationSettlement(userItem, data));
    }

    /**
     * 费用退费
     *
     * @param data 结算主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-02-20 16:26
     */
    @ApiOperation(value = "退费", notes = "对费用表charge_item中已结算记录id，进行退费操作，系统将产生未结算的退费记录信息")
    @PostMapping("/save-charge-settle-to-refund")
    public BaseResult saveChargeSettleToRefund(@RequestBody ChargeRefundData data) {
        return resultHandler(data, userItem -> chargeSettlementRefundService.saveChargeSettleToRefund(userItem, data));
    }

    /**
     * 更改结算记录收据号码信息
     *
     * @param data 新收据号数据
     * @return
     * @author LiCongLu
     * @date 2020-02-20 18:26
     */
    @ApiOperation(value = "更改结算记录收据号码信息", notes = "对费用结算表charge_settle中已结算记录，进行收据信息更改")
    @PostMapping("/save-charge-settle-change-receipt")
    public BaseResult saveChargeSettleChangeReceipt(@RequestBody ChangeReceiptData data) {
        return resultHandler(data, userItem -> chargeSettlementService.saveChargeSettleChangeReceipt(userItem, data));
    }

    /**
     * 打印费用明细接口
     *
     * @param data 打印明细IDS和业务编码
     * @return
     * @author ZhangLiRui
     * @date 2020/4/15 13:31
     */
    @ApiOperation(value = "根据funeral_dead表中businessCode和charge_item表中的费用项目id集合加载打印费用详情数据", notes = "根据funeral_dead表中businessCode和charge_item表中的费用项目id集合加载打印费用详情数据")
    @PostMapping("/load-print-charge-details-with-id")
    public BaseResult<ChargeDetailsItem> loadPrintChargeDetailsWithId(@RequestBody IdListData data) {
        return resultHandler(data, userItem -> chargeSettlementService.loadPrintChargeDetailsWithId(userItem, data));
    }

    /**
     * 打印结算明细
     *
     * @param data 打印结算明细通过ids和编码
     * @return
     * @author ZhangLiRui
     * @date 2020/4/16 16:33
     */
    @ApiOperation(value = "根据funeral_dead表中businessCode和charge_settle表中的费用项目id集合加载打印结算费用详情数据", notes = "根据funeral_dead表中businessCode和charge_settle表中的费用项目id集合加载打印结算费用详情数据")
    @PostMapping("/load-print-charge-settle-details-with-id")
    public BaseResult<ChargeSettleDetailsItem> loadPrintChargeSettleDetailsWithId(@RequestBody IdListData data) {
        return resultHandler(data, userItem -> chargeSettlementService.loadPrintChargeSettleDetailsWithId(userItem, data));
    }

    /**
     * 打印发票，选择结算费用打印发票
     *
     * @param data 结算主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-02-20 11:35
     */
    @ApiOperation(value = "打印发票", notes = "对结算表charge_settle中id版本，进行重打操作，更新发票状态")
    @PostMapping("/save-charge-settle-to-invoice")
    public BaseResult<ChargeInvoiceLoadData> saveChargeSettleToInvoice(@RequestBody ChargeInvoiceData data) {
        return resultHandler(data, userItem -> chargeSettlementInvoiceService.saveChargeSettleToInvoice(userItem, data));
    }

    /**
     * 根据funeral_dead表中businessCode加载逝者发票管理所有信息
     *
     * @param data 业务编码
     * @return
     * @author LiCongLu
     * @date 2020-05-14 10:59
     */
    @ApiOperation(value = "根据funeral_dead表中businessCode加载逝者发票管理所有信息，此接口为按页面定制接口", notes = "根据businessCode加载发票管理信息，信息包括：打印发票信息、冲红发票信息等记录信息")
    @PostMapping("/load-charge-invoice-all")
    public BaseResult<ChargeInvoiceAllLoadData> loadChargeInvoiceAll(@RequestBody BusinessCodeData data) {
        return resultHandler(data, userItem -> chargeSettlementInvoiceService.loadChargeInvoiceAll(data));
    }

    /**
     * 重打发票接口
     *
     * @param data 发票主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-05-14 11:33
     */
    @ApiOperation(value = "重打发票", notes = "对发票表charge_invoice中id版本，进行重打操作，更新发票状态")
    @PostMapping("/save-charge-invoice-to-reprint")
    public BaseResult<ChargeInvoiceLoadData> saveChargeInvoiceToReprint(@RequestBody ChargeInvoiceIdData data) {
        return resultHandler(data, userItem -> chargeSettlementInvoiceService.saveChargeInvoiceToReprint(userItem, data));
    }

    /**
     * 作废发票接口
     *
     * @param data 发票主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-05-14 13:11
     */
    @ApiOperation(value = "作废发票", notes = "对发票表charge_invoice中id版本，进行作废操作，更新发票状态")
    @PostMapping("/save-charge-invoice-to-cancellation")
    public BaseResult saveChargeInvoiceToCancellation(@RequestBody ChargeInvoiceIdData data) {
        return resultHandler(data, userItem -> chargeSettlementInvoiceService.saveChargeInvoiceToCancellation(userItem, data));
    }

    /**
     * 冲红接口
     *
     * @param data 发票数据及新发票信息
     * @return
     * @author LiCongLu
     * @date 2020-05-14 13:43
     */
    @ApiOperation(value = "冲红", notes = "对发票表charge_invoice中id集合和发票信息，进行冲红操作，产生一条负发票金额的冲红记录")
    @PostMapping("/save-charge-invoice-to-red")
    public BaseResult<ChargeInvoiceLoadData> saveChargeInvoiceToRed(@RequestBody ChargeInvoiceRedData data) {
        return resultHandler(data, userItem -> chargeSettlementInvoiceService.saveChargeInvoiceToRed(userItem, data));
    }

    /**
     * 重打红票
     *
     * @param data 红票主键和数据版本
     * @return
     * @author LiCongLu
     * @date 2020-05-14 14:11
     */
    @ApiOperation(value = "重打红票", notes = "对红票表charge_invoice_red中id版本，进行红票重打操作，更新发票状态")
    @PostMapping("/save-charge-invoice-red-to-reprint")
    public BaseResult<ChargeInvoiceLoadData> saveChargeInvoiceRedToReprint(@RequestBody ChargeInvoiceIdData data) {
        return resultHandler(data, userItem -> chargeSettlementInvoiceService.saveChargeInvoiceRedToReprint(userItem, data));
    }
}
